package com.wish233.wiliwilivideo.exception;

import com.wish233.wiliwilicommon.common.BaseResponse;
import com.wish233.wiliwilicommon.common.ErrorCode;
import com.wish233.wiliwilicommon.common.ResultUtils;
import com.wish233.wiliwilicommon.exception.BusinessException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author WHH
 */
@RestControllerAdvice
public class ConsoleExceptionHandler {


    @ExceptionHandler(BusinessException.class)
    public BaseResponse<?> handleBusinessException(BusinessException e) {
        return ResultUtils.error(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(RuntimeException.class)
    public BaseResponse<?> handleRunTimeException(RuntimeException e) {
        return ResultUtils.error(ErrorCode.SYSTEM_ERROR, e.getMessage());
    }

}